package org.linlinjava.litemall.admin.controller;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.beans.dto.ShopCheckDto;
import org.linlinjava.litemall.admin.service.ShopCheckService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理车间检查控制器
 *
 * @author yliyun
 * @Author: robb
 * @Date: 2019/11/2 11:25
 * @Version: 1.0
 * @Description: 店铺盘点管理controller
 * @date 2022/09/14
 */
@Api(tags = "门店API")
@RestController
@RequestMapping("/admin/shopCheck")
@Validated
public class AdminShopCheckController {

    /**
     * 店检查服务
     */
    @Autowired
    private ShopCheckService shopCheckService;


    /**
     * 所有门店
     *
     * @return {@link ResponseUtil.Response}
     */
    @ApiOperation("所有门店")
    @GetMapping("/getShopAll")
    @LogAnno
    public ResponseUtil.Response getShopAll(){
        return shopCheckService.getShopAll();
    }


    /**
     * 列表
     * 查询门店
     *
     * @param shopId    商店id
     * @param checkNo   检查没有
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @param page      页面
     * @param limit     限制
     * @param sort      排序
     * @param order     订单
     * @return {@link Object}
     */
    @GetMapping("/list")
    @LogAnno
    public Object list(@LoginAdminShopId Integer shopId,
    				   String checkNo,
    				   String startDate,
            		   String endDate,
                       String shopName,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return shopCheckService.list(shopId, checkNo, startDate, endDate,shopName, page, limit, sort, order);
    }

    /**
     * 创建
     * 添加门店
     *
     * @param shopCheckDto 店检查dto
     * @param shopId       商店id
     * @return {@link Object}
     */
    @PostMapping("/create")
    @LogAnno
    public Object create(@Valid @RequestBody ShopCheckDto shopCheckDto, @LoginAdminShopId Integer shopId) {
    	shopCheckDto.setShopId(shopId);
    	return shopCheckService.create(shopCheckDto);
    }

    /**
     * 读
     * 盘点详情
     *
     * @param id id
     * @return {@link Object}
     */
    @GetMapping("/read")
    @LogAnno
    public Object read(@NotNull Integer id) {
        return shopCheckService.read(id);
    }

}
